package com.itheima.controller;

import com.itheima.pojo.PageResult;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentContorller {

    @Autowired
    private StudentService studentService;


    //分页查询
    @GetMapping
    public Result getStudent(
            String name,
            String degree,
            Integer clazzId,
           @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize ) {
        //前端传递过来的五个数据name , degree , clazzId , page , pageSize
        PageResult<Student> pageResult = studentService.getStudent(name , degree , clazzId , page , pageSize);
        return Result.success(pageResult);

    }

    //删
    @DeleteMapping("/{ids}")
    public Result deleteStudent(@PathVariable List<Integer> ids){
        studentService.deleteStudent(ids);
        return Result.success();
    }
    //增
    @PostMapping
    public Result postStudent(@RequestBody Student student){
        studentService.postStudent(student);
        return Result.success();
    }

    //改之前的数据回显
    @GetMapping("/{id}")
    public Result getStudentById(@PathVariable Integer id){
     Student student = studentService.getStudentById(id);
     return Result.success(student);
    }
    @PutMapping
    public Result putStudent(@RequestBody Student student){
        studentService.putStudent(student);
        return Result.success();
    }
    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result disposeById(@PathVariable Integer id , Integer score){
        studentService.disposeById(id , score);
        return Result.success();
    }

}
